//页面加载
$('body').show();
$('.version').text(NProgress.version);
NProgress.start();
setTimeout(function () {
    NProgress.done();
    $('.fade').removeClass('out');
}, 1000);
//返回顶部按钮
$(function () {
    $(window).scroll(function () {
        if ($(window).scrollTop() > 100) {
            $(".gotop").fadeIn();
        } else {
            $(".gotop").hide();
        }
    });
    $(".gotop").click(function () {
        $('html,body').animate({'scrollTop': 0}, 500);
    });
});
//提示插件启用
$(function () {
    $('[data-toggle="popover"]').popover();
});
$(function () {
    $('[data-toggle="tooltip"]').tooltip();
});
//鼠标滑过显示 滑离隐藏
$(function () {
    $(".carousel").hover(function () {
        $(this).find(".carousel-control").show();
    }, function () {
        $(this).find(".carousel-control").hide();
    });
});
$(function () {
    $(".hot-content ul li").hover(function () {
        $(this).find("h3").show();
    }, function () {
        $(this).find("h3").hide();
    });
});
//页面元素智能定位
$.fn.smartFloat = function () {
    var position = function (element) {
        var top = element.position().top; //当前元素对象element距离浏览器上边缘的距离
        var pos = element.css("position"); //当前元素距离页面document顶部的距离
        $(window).scroll(function () { //侦听滚动时
            var scrolls = $(this).scrollTop();
            if (scrolls > top) { //如果滚动到页面超出了当前元素element的相对页面顶部的高度
                if (window.XMLHttpRequest) { //如果不是ie6
                    element.css({ //设置css
                        position: "fixed", //固定定位,即不再跟随滚动
                        top: 0 //距离页面顶部为0
                    }).addClass("shadow"); //加上阴影样式.shadow
                } else { //如果是ie6
                    element.css({
                        top: scrolls  //与页面顶部距离
                    });
                }
            } else {
                element.css({ //如果当前元素element未滚动到浏览器上边缘，则使用默认样式
                    position: pos,
                    top: top
                }).removeClass("shadow");//移除阴影样式.shadow
            }
        });
    };
    return $(this).each(function () {
        position($(this));
    });
};
//启用页面元素智能定位
$(function () {
    $("#search").smartFloat();
});
//异步加载更多内容
jQuery("#pagination a").on("click", function () {
    var _url = jQuery(this).attr("href");
    var _text = jQuery(this).text();
    jQuery(this).attr("href", "javascript:viod(0);");
    jQuery.ajax(
        {
            type: "POST",
            url: _url,
            success: function (data) {
                //将返回的数据进行处理，挑选出class是news-list的内容块
                result = jQuery(data).find(".row .news-list");
                //newHref获取返回的内容中的下一页的链接地址
                nextHref = jQuery(data).find("#pagination a").attr("href");
                jQuery(this).attr("href", _url);
                if (nextHref != undefined) {
                    jQuery("#pagination a").attr("href", nextHref);
                } else {
                    jQuery("#pagination a").html("下一页没有了").removeAttr("href")
                }
                // 渐显新内容
                jQuery(function () {
                    jQuery(".row").append(result.fadeIn(300));
                    jQuery("img").lazyload(
                        {
                            effect: "fadeIn"
                        });
                });
            }
        });
    return false;
});
var myTip = $("#myTip").val();
if (myTip == undefined) {
    javascript:;
} else if (myTip.trim() != "") {
    alert(myTip);
}
// setInterval("time()", 1000);
time();

var vWeek, vWeek_s, strDate;
vWeek = ["星期天", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];

function time() {
    var date = new Date();
    var year = date.getFullYear();
    var month = date.getMonth() + 1;
    var day = date.getDate();
    var hours = date.getHours();
    var minutes = date.getMinutes();
    var seconds = date.getSeconds();
    vWeek_s = date.getDay();
    switch (vWeek_s) {

        case 0: {

            strDate = "星期日"

        }
            break;

        case 1: {

            strDate = "星期一"

        }
            break;

        case 2: {

            strDate = "星期二"

        }
            break;

        case 3: {

            strDate = "星期三"

        }
            break;

        case 4: {

            strDate = "星期四"

        }
            break;

        case 5: {

            strDate = "星期五"

        }
            break;

        case 6: {

            strDate = "星期六"

        }
            break;

        case 7: {

            strDate = "星期日"

        }
            break;

    }
    $("#time").text(year + "年" + month + "月" + day + "日\t" + strDate);
}

$("a.feed-rss").click(function () {
    $("#tip").show().text("请您试下Ctrl+D看看行不行呢").addClass("alert").addClass("alert-info");
    $("a.feed-rss,a.feed-txweibo").addClass("noclick");
    var timer = setInterval(threeSecondClose, 1000);
    var second = 3;

    function threeSecondClose() {
        second -= 1;
        if (second == 0) {
            $("a.feed-rss,a.feed-txweibo").removeClass("noclick");
            $("#tip").removeClass("alert").removeClass("alert-info").text("");
            clearInterval(timer);
        }
    }
});
$("a.feed-txweibo").click(function () {
    $("#tip").show().text("站长腾讯微博已关闭服务,如有需要请点击新浪微博").addClass("alert").addClass("alert-info");
    $("a.feed-rss,a.feed-txweibo").addClass("noclick");
    var timer = setInterval(threeSecondClose, 1000);
    var second = 3;

    function threeSecondClose() {
        second -= 1;
        if (second == 0) {
            $("a.feed-rss,a.feed-txweibo").removeClass("noclick");
            $("#tip").removeClass("alert").removeClass("alert-info").text("");
            clearInterval(timer);
        }
    }
});
$("#openSidebar,#openSidebar1").click(function () {
    $(".myCanvasNav").show();
    $(".myCanvasNav").animate({left: '0px'});
});
$(".canvi-user-info__close").click(function () {
    $(".myCanvasNav").animate({left: '-320px'});
});
$("#fixInfo").mouseover(function () {
    $(this).css("color", "deepskyblue");
}).mouseleave(function () {
    $(this).css("color", "#319ACA");
}).click(function () {
    $(".contact-content:eq(0) p").fadeOut("slow");
    $("#userInfo").show("slow");
});
$("#userInfo").submit(function () {
    var flag = true;
    var userid = $("input[name='userid']").val();
    var username = $("input[name='username']").val();
    var useremail = $("input[name='useremail']").val();
    var userphone = $("input[name='userphone']").val();
    if (username.trim() != "") {
        $.ajax({
            type: "POST",
            url: "/user/checkUserName",
            data: {userName: username, userId: userid},
            dataType: "json",
            async: false,
            success: function (data) {
                if (data.flag == "true") {
                    $("input[name='username']").css("border", "1px solid red");
                    alert("用户名已存在");
                    flag = false;
                }
            }
        });
    } else {
        alert("用户名不能为空");
        flag = false;
    }
    if (!flag) {
        return false;
    }
    if (useremail.trim() != "") {
        $.ajax({
            type: "POST",
            url: "/user/checkEmail",
            data: {userEmail: useremail, userId: userid},
            dataType: "json",
            async: false,
            success: function (data) {
                if (data.flag == "true") {
                    $("input[name='useremail']").css("border", "1px solid red");
                    alert("邮箱已被使用");
                    flag = false;
                }
            }
        });
    } else {
        alert("邮箱不能为空");
        flag = false;
    }
    if (!flag) {
        return false;
    }
    if (userphone.trim() != "") {
        $.ajax({
            type: "POST",
            url: "/user/checkPhone",
            data: {userPhone: userphone, userId: userid},
            dataType: "json",
            async: false,
            success: function (data) {
                if (data.flag == "true") {
                    $("input[name='userphone']").css("border", "1px solid red");
                    alert("手机号已被使用");
                    flag = false;
                }
            }
        });
    } else {
        alert("手机号不能为空");
        flag = false;
    }
    return flag;
});
$("#practicalWeb-from").submit(function () {
    var webReg = /^(http:\/\/|https:\/\/)www\.[\w-]+\.[A-Za-z]{3,4}$/;
    var webname = $("input[name='webname']").val();
    var webhref = $("input[name='webhref']").val();
    var webintroduce = $("textarea[name='webintroduce']").val();
    if (webname.trim() == "") {
        alert("网站每项都不能为空");
        return false;
    }
    if (webhref.trim() == "") {
        alert("网站每项都不能为空");
        return false;
    }
    if (webintroduce == undefined || webintroduce.trim() == "") {
        alert("网站每项都不能为空");
        return false;
    }
    if (!webReg.test(webhref)) {
        alert("请输入正确格式的网址\n(http://www.***.com&https://www.***.com&)");
        return false;
    }
    return true;
});

$("img.userImages").click(function () {
    const uid = $(this).parent().find("input[name='uid']").val();
    location.href = "/page/about?visitor=1&uid=" + uid;
});

$("form.navbar-form").submit(function () {
    var searchContent = $("input[name='searchContent']").val();
    if (searchContent.trim() == "") {
        alert("搜索内容不能为空");
        return false;
    } else {
        return true;
    }
});